﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GomeeSoft.src.classes;

namespace GomeeSoft.src.control
{
    public partial class UCButton : UserControl
    {
        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public override string Text
        {
            get
            {
                return label1.Text;
            }
            set
            {
                label1.Text = value;
                RelocateLabel();
            }
        }
        public UCButton()
        {
            InitializeComponent();
            label1.BackColor = Color.Transparent;
            label1.ForeColor = Global.GetColor(Global.UCButtonForeColor);
            label1.Text = Name;
        }

        private void UCButton_Resize(object sender, EventArgs e)
        {
            RelocateLabel();
        }

        private void RelocateLabel()
        {
            label1.Left = (Width - label1.Width) / 2;
            label1.Top = (Height - label1.Height) / 2;
            Invalidate();
        }

        private void UCButton_Paint(object sender, PaintEventArgs e)
        {
            SolidBrush brush = new SolidBrush(Global.GetColor(Global.UCButtonBackColor));
            Pen pen;
            Graphics graphics = e.Graphics;
            graphics.FillRectangle(brush, new Rectangle(1, 1, Width - 2, Height - 2));
            pen = new Pen(Global.GetColor(Global.UCButtonBorderLight));
            graphics.DrawLine(pen, 2, 0, Width - 3, 0);
            graphics.DrawLine(pen, 0, 2, 0, Height - 3);
            graphics.DrawLine(pen, 2, 0, 0, 2);
            graphics.DrawLine(pen, Width - 3, 0, Width - 1, 2);
            graphics.DrawLine(pen, 0, Height - 3, 2, Height - 1);
            pen = new Pen(Global.GetColor(Global.UCButtonBorderDark));
            graphics.DrawLine(pen, 2, Height - 1, Width - 3, Height - 1);
            graphics.DrawLine(pen, Width - 1, 2, Width - 1, Height - 3);
            graphics.DrawLine(pen, Width - 3, Height - 1, Width - 1, Height - 3);
            brush.Dispose();
            pen.Dispose();
        }

        public event MouseEventHandler ButtonClick;

        private void UCButton_Click(object sender, MouseEventArgs e)
        {
            if (ButtonClick != null)
                ButtonClick(sender, e);
        }

        private void label1_Click(object sender, MouseEventArgs e)
        {
            if (ButtonClick != null)
                ButtonClick(sender, e);
        }
    }
}
